{% extends 'admin/admin_base.html' %}

{% block title %}查看试卷 - 后台管理系统{% endblock %}

{% block nav_exams %}active{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>查看试卷: {{ exam.name }}</h2>
        <div>
            <a href="{{ url_for('admin.exam_edit', exam_id=exam._id) }}" class="btn btn-primary">
                <i class="fas fa-edit"></i> 编辑试卷
            </a>
            <a href="{{ url_for('admin.exam_list') }}" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i> 返回列表
            </a>
        </div>
    </div>

    <!-- 试卷信息卡片 -->
    <div class="card mb-4">
        <div class="card-header bg-primary text-white">
            <h5 class="mb-0">试卷基本信息</h5>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-md-4">
                    <p><strong>试卷名称:</strong> {{ exam.name }}</p>
                </div>
                <div class="col-md-4">
                    <p><strong>科目:</strong> {{ exam.subject|upper }}</p>
                </div>
                <div class="col-md-4">
                    <p>
                        <strong>难度:</strong>
                        {% for i in range(exam.difficulty|default(1, true)) %}
                        <i class="fas fa-star text-warning"></i>
                        {% endfor %}
                    </p>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4">
                    <p>
                        <strong>题目数量:</strong>
                        {% set question_counts = {'single': 0, 'multiple': 0, 'boolean': 0} %}
                        {% for question in exam.questions %}
                            {% if question.type == 'single' %}
                                {% set _ = question_counts.update({'single': question_counts.single + 1}) %}
                            {% elif question.type == 'multiple' %}
                                {% set _ = question_counts.update({'multiple': question_counts.multiple + 1}) %}
                            {% elif question.type == 'boolean' %}
                                {% set _ = question_counts.update({'boolean': question_counts.boolean + 1}) %}
                            {% endif %}
                        {% endfor %}
                        单选题: {{ question_counts.single }}
                        多选题: {{ question_counts.multiple }}
                        判断题: {{ question_counts.boolean }}
                    </p>
                </div>
                <div class="col-md-4">
                    <p><strong>创建时间:</strong> {{ exam.created_at }}</p>
                </div>
            </div>
        </div>
    </div>

    <!-- 题目列表 -->
    <div class="card">
        <div class="card-header bg-primary text-white">
            <h5 class="mb-0">题目列表</h5>
        </div>
        <div class="card-body">
            <div class="list-group">
                {% for question in exam.questions %}
                <div class="list-group-item list-group-item-action">
                    <div class="d-flex w-100 justify-content-between align-items-center">
                        <h5 class="mb-1">
                            {% if question.type == 'single' %}
                                <span class="badge bg-primary">单选题</span>
                            {% elif question.type == 'multiple' %}
                                <span class="badge bg-success">多选题</span>
                            {% elif question.type == 'boolean' %}
                                <span class="badge bg-info">判断题</span>
                            {% endif %}
                            第 {{ loop.index }} 题
                        </h5>
                        <a href="{{ url_for('admin.question_view', exam_id=exam._id, question_index=loop.index0) }}" class="btn btn-sm btn-outline-primary">
                            查看详情
                        </a>
                    </div>
                    <p class="mb-1">
                        {% if question.has_image %}
                        <img src="{{ question.image_path }}" alt="题目图片" class="img-fluid mb-2" style="max-height: 100px;">
                        <br>
                        {% endif %}
                        {{ question.title }}
                    </p>
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
